package com.apes.autoparts.product.repository;

import com.apes.autoparts.product.model.OilyProduct;
import com.apes.framework.jpa.repository.CustomRepository;
import org.springframework.data.jpa.repository.Query;

import java.util.List;
import java.util.Map;
import java.util.Set;

/**
 * 类描述：
 *
 * @ClassName oilyProductRepository
 * @Description 描述
 * @Author wushilong
 * @Date 2022/10/26 17:39
 * @Version 1.0
 */
public interface OilyProductRepository extends CustomRepository<OilyProduct, String> {

    @Query(value = "SELECT A.* FROM AUTO_OILY_PRODUCT A , (SELECT MAX(ID) AS ID FROM AUTO_OILY_PRODUCT \n" +
            "GROUP BY BRAND, API_CLASS, CAPACITY, TYPE, VISCOSITY_CLASS )B WHERE A.ID = B.ID", nativeQuery = true)
    List<OilyProduct> findAllByStandard();

    @Query(value = "select a.id as id from OilyProduct a")
    Set<String> findAllId();

    @Query(value = "select o from OilyProduct o where o.brand = :brand and o.viscosityClass = :viscosityClass and o.apiClass = :apiClass and o.type = :type and o.capacity = :capacity")
    OilyProduct findByBrand(String brand, String viscosityClass, String apiClass, String type, Double capacity);
}
